package slim3.demo.controller.six;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;


public class AllLogoTimeController extends Controller {



//    public static void main(String[] argv) throws Exception{
//        
//        ReadXMLFile test = new ReadXMLFile();
//        ArrayList<FlightBean> beans = test.getKNH();
//        ArrayList<FlightBean> beans = test.getMFKandLZN();
//        
//        for (int i=0; i<beans.size(); i++) {
//            System.out.println(beans.get(i));
//        }
//        
//    }
    
    @Override
    public Navigation run() throws Exception {

        ReadXMLFile read = new ReadXMLFile();
        ArrayList<FlightBean> beans = read.getAll();

        //update times from UNI Airways
//        UNIAirTime uni = new UNIAirTime();
//        beans = uni.updateHCN(beans);
//        beans = uni.updateKNH(beans);
//        beans = uni.updateLZN(beans);
//        beans = uni.updateMFK(beans);
//        beans = uni.updateMZG(beans);
//        beans = uni.updateTTT(beans);

        //update times from TransAsia Airways
//        TransAsiaTime ge = new TransAsiaTime();
//        beans = ge.updateHUN(beans);
//        beans = ge.updateKNH(beans);
//        beans = ge.updateMZG(beans);

        requestScope("flightlist", beans);
        
        
        //get airport status
//        AirportStatus as = new AirportStatus();
//        ArrayList<AirportBean> airportBeans = as.getAirportStatus();
//        requestScope("airportlist", airportBeans);
        
        
        //time
        Date date = new Date();
        DateFormat secondFormat = new SimpleDateFormat("yyyy M d HH mm ss");
        TimeZone secondTime = TimeZone.getTimeZone("Asia/Taipei");
        secondFormat.setTimeZone(secondTime);
        
        String t = secondFormat.format(date);
        
        String [] ts = t.split(" ");
        
        String year = ts[0];
        int temp = Integer.valueOf(year);
        temp = temp - 1911;
        year = temp + "";
        
        String month = ts[1];
        String day = ts[2];
        String hour = ts[3];
        String minute = ts[4];
        String second = ts[5];
                
        requestScope("year", year);
        requestScope("month", month);
        requestScope("day", day);
        requestScope("hour", hour);
        requestScope("minute", minute);
        requestScope("second", second);
                
        return forward("/six/all-logo-time.jsp");
    }
}